package org.gotson.komga.interfaces.api.rest.dto

import org.gotson.komga.domain.model.Library
import org.gotson.komga.infrastructure.web.toFilePath

data class LibraryDto(
  val id: String,
  val name: String,
  val root: String,
  val importComicInfoBook: Boolean,
  val importComicInfoSeries: Boolean,
  val importComicInfoCollection: Boolean,
  val importComicInfoReadList: Boolean,
  val importComicInfoSeriesAppendVolume: Boolean,
  val importEpubBook: Boolean,
  val importEpubSeries: Boolean,
  val importMylarSeries: Boolean,
  val importLocalArtwork: Boolean,
  val importBarcodeIsbn: Boolean,
  val scanForceModifiedTime: Boolean,
  val scanInterval: ScanIntervalDto,
  val scanOnStartup: Boolean,
  val scanCbx: Boolean,
  val scanPdf: Boolean,
  val scanEpub: Boolean,
  val scanDirectoryExclusions: Set<String>,
  val repairExtensions: Boolean,
  val convertToCbz: Boolean,
  val emptyTrashAfterScan: Boolean,
  val seriesCover: SeriesCoverDto,
  val hashFiles: Boolean,
  val hashPages: Boolean,
  val hashKoreader: Boolean,
  val analyzeDimensions: Boolean,
  val oneshotsDirectory: String?,
  val unavailable: Boolean,
)

fun Library.toDto(includeRoot: Boolean) =
  LibraryDto(
    id = id,
    name = name,
    root = if (includeRoot) this.root.toFilePath() else "",
    importComicInfoBook = importComicInfoBook,
    importComicInfoSeries = importComicInfoSeries,
    importComicInfoCollection = importComicInfoCollection,
    importComicInfoReadList = importComicInfoReadList,
    importComicInfoSeriesAppendVolume = importComicInfoSeriesAppendVolume,
    importEpubBook = importEpubBook,
    importEpubSeries = importEpubSeries,
    importMylarSeries = importMylarSeries,
    importLocalArtwork = importLocalArtwork,
    importBarcodeIsbn = importBarcodeIsbn,
    scanForceModifiedTime = scanForceModifiedTime,
    scanInterval = scanInterval.toDto(),
    scanOnStartup = scanOnStartup,
    scanCbx = scanCbx,
    scanPdf = scanPdf,
    scanEpub = scanEpub,
    scanDirectoryExclusions = scanDirectoryExclusions,
    repairExtensions = repairExtensions,
    convertToCbz = convertToCbz,
    emptyTrashAfterScan = emptyTrashAfterScan,
    seriesCover = seriesCover.toDto(),
    hashFiles = hashFiles,
    hashPages = hashPages,
    hashKoreader = hashKoreader,
    analyzeDimensions = analyzeDimensions,
    oneshotsDirectory = oneshotsDirectory,
    unavailable = unavailableDate != null,
  )
